<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>会员充值</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="{:sysconf('browser_icon')}"/>
    <link rel="stylesheet" href="__STATIC__/plugs/layui/css/layui.css?ver={:date('ymd')}"/>
    <script src="__STATIC__/plugs/jquery/jquery.min.js?ver={:date('ymd')}"></script>
    <script src="__STATIC__/plugs/jquery/jquery.jqprint-0.3.js?ver={:date('ymd')}"></script>
</head>
<body>
<form class="layui-form layui-form-pane" action="" method="post">
      <div class="layui-col-xs12">
          <div class="grid-demo grid-demo-bg1">
              <div class="layui-form-item">
                  <label class="layui-form-label">会员手机</label>
                  <div class="layui-input-block">
                      <input id="mobile" type="text" name="mobile" placeholder="请输入会员手机号码" lay-verify="require|phone" autocomplete="off" class="layui-input" >
                  </div>
              </div>
          </div>
      </div>
      <div class="layui-col-xs12">
          <div class="grid-demo grid-demo-bg1">
              <div class="layui-form-item">
                  <label class="layui-form-label">充值金额</label>
                  <div class="layui-input-block">
                      <input id="amount" type="text" name="amount" placeholder="请输入充值金额" lay-verify="require|amount" autocomplete="off" class="layui-input" >
                  </div>
              </div>
          </div>
      </div>

      <div class="layui-form-item" pane>
          <div class="layui-inline">
              <label class="layui-form-label">付款方式</label>
              <div class="layui-input-block">
                  <input type="radio" name="pay_type" value="1" title="支付宝">
                  <input type="radio" name="pay_type" value="2" title="微信">
                  <input type="radio" name="pay_type" value="4" title="现金">
                  <input type="radio" name="pay_type" value="5" title="银行卡">
              </div>
          </div>
      </div>
      <div class="layui-form-item">
          <div class="layui-input-block">
              <input type="button" class="layui-btn" lay-submit lay-filter="demo1" id="sub" onclick="checkform()" value="提交">
          </div>
      </div>
</form>
<script src="__STATIC__/plugs/layui/layui.all.js" charset="utf-8"></script>
<script>
    /**
     * 检查表单信息
     */
    function checkform(){
        var reg = /^1[34578]\d{9}$/;
        var reg_amount = /^\d+(\.\d{1,2})?$/;
        if ($('input[name=mobile]').val() == '') {
            layer.msg('请输入手机号', {icon: 2, time: 1000});
            return false;
        }
        if(!reg.test($('input[name=mobile]').val())){   //正则验证手机号
            layer.msg('手机格式有误，请重新输入！', {icon: 2, time: 1000});
            return false;
        }

        if ($('input[name=amount]').val() == '') {
            layer.msg('请输入充值金额', {icon: 2, time: 1000});
            return false;
        }

        if(!reg_amount.test($('input[name=amount]').val())){   //正则验证手机号
            layer.msg('充值金额输入有误，请重新输入', {icon: 2, time: 1000});
            return false;
        }

        if($('input[name=pay_type]').val() == undefined){
            layer.msg('请选择付款方式', {icon: 2, time: 1000});
            return false;
        }

        $.post("{:url('Index/recharge')}"

        );

    }
//    layui.use(['form', 'layedit', 'laydate'], function () {
//        var form = layui.form
//            , layer = layui.layer
//            , layedit = layui.layedit
//            , laydate = layui.laydate,
//            , reg = /^1[34578]\d{9}$/;
//
//        //自定义验证规则
//        form.verify({
//            amount: [/^\d+(\.\d{1,2})?$/, '充值金额有误，请重新输入']
//        });
//
//        //监听提交
//        form.on('submit(demo1)', function (data) {
//            alert('sss');
//            if (data.field.mobile == '') {
//                layer.msg('请输入手机号', {icon: 2, time: 1000});
//                return false;
//            }
//            if(!reg.test(data.field.mobile)){   //正则验证手机号
//                layer.msg('手机格式有误，请重新输入！', {icon: 2, time: 1000});
//                return false;
//            }
//            if (data.field.pay_type == undefined) {
//                layer.msg('请选择支付方式', {icon: 2, time: 1000});
//                return false;
//            }
//
//            return false;
//        });
//    });
</script>

</body>
</html>
